package com.acme.bankapp.domain.bank;

/**
 * This class defines simple saving account.
 * @author Artem Nikitin
 *
 */
public class SavingAccount extends AbstractAccount {

	public SavingAccount(int id, double balance) {
		super(id, balance);
	}
	
	/**
	 * Deposits specified amount of funds.
	 * @param amount - amount of funds to deposit
	 * @throws IllegalArgumentException - If {@code amount} is negative
	 */
	public void deposit(double amount) {
		if (amount < 0) {
			throw new IllegalArgumentException("Amount cannot be negative");
		}
		
		balance += amount;
	}

	/**
	 * Withdraw specified amount of funds. If there isn't enough funds throws {@code NotEnoughFundsException}
	 * @param amount - amount of funds to withdraw
	 * @throws NotEnoughFundsException - if there isn't enough funds to withdraw
	 * @throws IllegalArgumentException - if {@code amount} is negative
	 */
	public void withdraw(double amount) throws NotEnoughFundsException {
		if (amount < 0) {
			throw new IllegalArgumentException("Amount cannot be negative");
		}
		
		if (balance < amount) {
			throw new NotEnoughFundsException(amount);
		} else {
			balance -= amount;
		}
	}

	public double maxAmountToWithdraw() {
		return getBalance();
	}

}
